package com.easy.service.impl;

import com.easy.bean.User;
import com.easy.dao.UserDao;
import com.easy.service.IShoppingLoginService;
import com.easy.util.Page;
import com.easy.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ShoppingLoginService implements IShoppingLoginService {
    @Autowired
    UserDao userDao;
    @Override
    public User dologin(User user) {
        User user_data=userDao.getUserByUsername(user.getUsername());
        if(user_data==null){
            throw new RuntimeException("没有此账号");
        }
        if(!SYS.checkPass(user.getPassword(),user_data.getPassword())){
            throw new RuntimeException("密码不正确");
        }
        /*if(!user.getPassword().equals(user_data.getPassword())){
            throw new RuntimeException("密码不正确");
        }*/
        return user_data;

    }

    @Override
    public int add(User user) {
        return userDao.add(user);
    }

    @Override
    public int edit(User user) {
        return userDao.edit(user);
    }

    @Override
    public int delete(int id) {
        return userDao.delete(id);
    }

    @Override
    public List<User> getList(Page page, String text,int id) {
        return userDao.getList(page, text,id);
    }

    @Override
    public List<User> getList1(Page page, String text) {
        return userDao.getList1(page,text);
    }

    @Override
    public User getUserById(int id) {
        return userDao.getUserById(id);
    }

    @Override
    public int getCount(String text,int id) {
        return userDao.getCount(text,id);
    }

    @Override
    public int getCount1(String text) {
        return userDao.getCount1(text);
    }

    @Override
    public User getUser(User user) {
        return userDao.getUserByUsername(user.getUsername());
    }

    @Override
    public int updatePassword(User user) {
        return userDao.updatePassword(user);
    }
}


